<?php
	//No direct access
	defined('_JEXEC') or die('Restricted access');
?>
<div id="ownservices">
<div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>
<div id="mainownservice">
<h3><?php echo JText::_('OWNSERVICE_PAID_TRANSACTIONS'); ?></h3>
<hr />
<script language="javascript" type="text/javascript">
	<!--
		function submitbutton(pressbutton)
		{
			var form = document.adminForm;

			if (form.boxchecked.value == 0){
				alert( "<?php echo JText::_( 'OWNSERVICE_SELECT_PAID_TRANSACTIONS', true ); ?>" );
			} else {
				submitform( pressbutton );
			}
		}
	//-->
</script>
<div id="toolbar">
	<a class="toolbar" onclick="submitbutton('approval');" href="#">
		<span title="<?php echo JText::_('OWNSERVICE_REQUEST_APPROVEL'); ?>" class="icon-32-forward"></span>
		<?php echo JText::_('OWNSERVICE_REQUEST_APPROVEL'); ?>
	</a>
</div>
<div class="clear"> </div>
<form action="<?php echo JRoute::_('index.php?option=com_ownservice'); ?>" method="post" name="adminForm">
		<table>
			<tr>
				<td width="100%">
					<?php echo JText::_( 'OWNSERVICE_FILTER' ); ?>:<input type="text" name="search" value="<?php echo htmlspecialchars($this->lists['search']);?>"  onchange="document.adminForm.submit();" />
					<button onclick="this.form.submit();" class="button">
						<?php echo JText::_( 'Go' ); ?>
					</button>
					<button onclick="document.adminForm.search.value='';this.form.submit();" class="button">
						<?php echo JText::_( 'Reset' ); ?>
					</button>
				</td>
				<td nowrap="nowrap">
					<?php if( isset($this->lists['branch']) ) :?>
							<?php echo $this->lists['branch']; ?>
					<?php endif; ?>
				</td>
			</tr>
		</table>
	<table class="adminlist" cellspacing="1">
		<tr>
			<td align="center" class="tablelist"><?php echo JText::_('NUM'); ?></td>
			<td align="center" class="tablelist">
				<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->rows); ?>);" />
			</td>
			<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_RECEIVER_NO'); ?></td>
			<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_ACCOUNT_NO'); ?></td>
			<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_BANK_NAME'); ?></td>
			<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_BRANCH_CITY'); ?></td>
			<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_USER'); ?></td>
			<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_CREATE_DATE'); ?></td>
			<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_AMOUNT_TRANSFER'); ?><br />(AUD)</td>
			<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_RATE'); ?></td>
			<td align="center" class="tablelist"><?php echo JText::_('OWNSERVICE_TOTAL_EXCHANGE'); ?></td>
		</tr>
		<?php/*<tfoot>
			<tr>
			  <td colspan="9"><?php echo $this->pageNav->getListFooter(true); ?></td>
			</tr>
		</tfoot>*/?>
		<tbody>
		<?php
			$k = 0;
			$sum_amount	= 0;
			$sum_rate	 	= 0;
			$sum_total		= 0;
			$priceformat = OwnserviceHelper::getParams('price_format', '#,###.##');
			$dateformat  = OwnserviceHelper::getParams('date_format', '%d/%m/%Y'); 
			for($i=0,$n=count($this->rows);$i<$n;$i++):
			 
			 $row = $this->rows[$i];
			 $checked = JHTML::_('grid.checkedout', $row, $i );
		?>
		<tr class="<?php echo "row$k"; ?>">
			<td align="center" class="inner_tablelist"><?php echo /*$this->pageNav->getRowOffset( $i )*/ ($i+1); ?></td>
			<td align="center" class="inner_tablelist"><?php echo $checked; ?></td>
			<td align="center" class="inner_tablelist">
				<a href="<?php echo JRoute::_('index.php?option=com_ownservice&controller=transaction&task=detail&id='.$row->id); ?>">
					<?php echo $row->invoice; ?>
				</a>
			</td>
			<td align="center" class="inner_tablelist">
				<?php echo OwnserviceHelper::accountFormat($row->account); ?>
			</td>
			<td align="center" class="inner_tablelist">
				<?php if($row->bank_name=='other'): ?>
					<?php echo $row->bank_other; ?>
				<?php else: ?>
					<?php echo $row->bank_name; ?>
				<?php endif; ?>
			</td>
			<td align="center" class="inner_tablelist">
				<?php echo $row->branch_city; ?>
			</td>
			<td class="inner_tablelist">
				<a href="<?php echo JRoute::_('index.php?option=com_ownservice&controller=member&task=detail&id='.$row->memberid); ?>">
					<?php echo $row->username; ?>
				</a>
			</td>
			<td align="center" class="inner_tablelist">
				<?php echo JHTML::_('date', $row->created, $dateformat); ?>
			</td>
			<td class="inner_tablelist" align="center">
				<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->amount); ?>
				<?php $sum_amount = $sum_amount + $row->amount; ?>
			</td>
			<td class="inner_tablelist" align="right">
			<?php
				$color ='';
				if($row->extrarate > 0.00) {
					$color ='red';
				} else if($row->extrarate < 0.00) {
					$color ='green';
				}
			?>
			<?php if(!$row->iscore): ?>
				<div style="border-bottom: 1px solid;">
					<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate_th); ?> THB
				</div>
			<?php endif; ?>
			<div>
				<span class ="<?php echo $color; ?>"><?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate+$row->extrarate); ?></span>
				<?php echo $row->rate_code; ?> 
			</div>
			</td>
			<td class="inner_tablelist" align="right">
			<?php if(!$row->iscore): ?>
			<div style="border-bottom: 1px solid;">
				<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->total_th); ?> THB
				<?php $sum_total = $sum_total + $row->total_th; ?>
			</div>
			<?php else: ?>
				<?php
					if($row->extratotal > 0.00 ){
						$sum_total = $sum_total + $row->extratotal;	
					} else {
						$sum_total = $sum_total + ( ($row->amount * ($row->rate+$row->extrarate)) - ($row->bankfee+$row->extrabfee));  
					}
				?>
			<?php endif; ?>
			<div>
			<span class="<?php echo ($row->extratotal > 0.00?'red':''); ?>">
				<?php
					if($row->extratotal > 0.00) {
						echo OwnserviceHelper::moneyFormat($priceformat, $row->extratotal);
					} else {
						echo OwnserviceHelper::moneyFormat($priceformat,( ($row->amount * ($row->rate+$row->extrarate)) - ($row->bankfee+$row->extrabfee))); 
					}
				?>
			</span> <?php echo $row->rate_code; ?>
			</div>
			</td>
		</tr>
		<?php $k = 1 - $k;  endfor; ?>
		<tr>
			<td colspan="8" align="right">
				<strong><?php echo JText::_('OWNSERVICE_TOTAL'); ?></strong>
			</td>
			<td align="center" style="font-weight: bold;">
				<?php echo OwnserviceHelper::moneyFormat($priceformat,$sum_amount); ?>
			</td>
			<td align="right">
			</td>
			<td align="right" style="font-weight: bold;">
				<?php echo OwnserviceHelper::moneyFormat($priceformat,$sum_total). ' THB'; ?>
			</td>
		</tr>
		</tbody>
	</table>
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="id" value="" />
	<input type="hidden" name="status" value="" />
	<input type="hidden" name="option" value="com_ownservice" />
	<input type="hidden" name="task" value="paidtransactions" />
	<input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid'); ?>" />
	<input type="hidden" name="controller" value="transaction" />
	<input type="hidden" name="view" value="transactions" />
	<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
	<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>
</div>
</div>